package com.project.controller;


import com.github.pagehelper.PageInfo;
import com.project.ResultVO;
import com.project.mapper.SuppliersDto;
import com.project.remote.ISupplierRemoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("supplier")
@Api(tags = "供应商测试接口")
public class SuppliersController {
    @Autowired
    private ISupplierRemoteService supplierRemoteService;

    @GetMapping("findByItem")
    @ApiOperation(value = "按选项分页查找供应商")
    public PageInfo<SuppliersDto> findByItem(int page,
                                             int pageSize,
                                             String name,
                                             String range){
        if (name == null || name.equals("")){
            name = "$";
        }
        if (range == null || range.equals("")){
            range = "$";
        }
        return supplierRemoteService.findByItem(page,pageSize,name,range);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResultVO add(SuppliersDto supplier){
        return supplierRemoteService.add(supplier);
    }

    @GetMapping("findById")
    @ApiOperation(value = "按id查询供应商信息")
    public SuppliersDto findById(int id){
        return supplierRemoteService.findById(id);
    }

    @PutMapping("update")
    @ApiOperation(value = "修改供应商信息")
    public ResultVO update(SuppliersDto supplier){
        return supplierRemoteService.update(supplier);
    }

}
